import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;

import javax.swing.JOptionPane;

public class Compiler {

	static String token;
	static char nextChar;
	static String thisline;
	static String filename;
	static StringBuilder stringbuilder = new StringBuilder();
	static MySyntaxAnalyzer syntax = new MySyntaxAnalyzer();

	public static void main(String[] args) throws CompilerException, IOException {
		// checks to see if file is .mkd extension
		BufferedReader buffer = null;
		filename = args[0];
		String extension = filename.substring(filename.lastIndexOf(".") + 1,
				filename.length());

		String mkd = "mkd";
		if (!mkd.equals(extension)) {
			throw new IOException("Not a .mkd extension!");
		} 
		// if .mkd extension, read file into string
		else {
			try {
				buffer = new BufferedReader(new FileReader(filename));
				while ((thisline = buffer.readLine()) != null) {
					stringbuilder.append(thisline);
					System.out.println(thisline);
				}
			} catch (IOException e) {
				e.printStackTrace();
			}
			// Empties the token string and calls the Syntax analyzer
			token = "";
			syntax.document();
			// Calls the semantic analyzer after the parse tree has been created
			SemanticAnalyzer semantic = new SemanticAnalyzer();
			semantic.html();
		}
	}
}
